
MOD_MEMB_ACCESS_READ		equ 1
MOD_MEMB_ACCESS_WRITE		equ 2
MOD_MEMB_ACCESS_CALL		equ 4

MOD_MEMB_RET_TYPE_ADDRESS	equ 0
MOD_MEMB_RET_TYPE_FUNC		equ 1

;----------------------------------------------------

_@module_fixe	struc
	addr_to_fixe	dd 0
	id		dd 0
	lpNextFixe	dd 0
_@module_fixe	ends


_@module_member	struc
	memb_flags			dd 0
	lpszModMembName			dd 0
	lpszModMembDoc			dd 0
	;---------------
	lpModule			dd 0
	;---------------
	memb_type			dd 0
	lp_func_params_types_list	dd 0
	func_params_types_list_len	dd 0
	lp_func_returns_types_list	dd 0
	func_returns_types_list_len	dd 0
	;---------------
	lpAddress			dd 0
	;---------------
	lpFirstFixe			dd 0

	lpFirstPostfixe_r		dd 0
	lpFirstPostfixe_w		dd 0
	lpFirstPostfixe_c		dd 0
	
	offset_from_begin		dd 0
	;---------------
	lpToCallMemb_paramList_firstMember dd 0
	lpToCallMemb_retVal_firstMember dd 0
	;---------------
	lpNextModuleMember		dd 0
_@module_member		ends

;----------------------------------------------------


.code

module_memb_get	proc lpModule,lpSzMembName,access_type
			push edi
			push esi
			push ebx
			push ecx

			mov eax,lpModule
			test eax,eax
			jz  mmgExit;short
			mov esi,eax
		assume esi: ptr _@module

			xor eax,eax

			mov ebx,lpSzMembName
			test ebx,ebx
			jz  mmgExit;short

			cmp byte ptr [ebx],0
			jz  mmgExit;short
			
			lea esi,[esi].lpFirstMember

			mov eax,access_type
		mmgAccess_isRead:
			dec eax
			jnz short mmgAccess_isWrite

			mov ecx,MOD_MEMB_ACCESS_READ
			jmp short mmgFindThisMember
			
		mmgAccess_isWrite:
			dec eax
			jnz short mmgAccess_isCall

			mov ecx,MOD_MEMB_ACCESS_WRITE
			jmp short mmgFindThisMember
			
		mmgAccess_isCall:
			dec eax
			jnz short mmgAccess_is???

			mov ecx,MOD_MEMB_ACCESS_CALL
			jmp short mmgFindThisMember
			
		mmgAccess_is???:
			xor eax,eax
			jmp  mmgExit;short

	mmgFindThisMember:
		assume eax: ptr _@module_member

			mov edi,esi

		mmgSeekThisMember_b:
			mov eax,dword ptr [esi]
			test eax,eax
			jz short mmgAddNewMemberToModule

			lea esi,[eax].lpNextModuleMember

				push eax
				push ebx
				push ecx

			push [eax].lpszModMembName
			push ebx
			call strcmp
;			add esp,4*2
			test eax,eax
				pop ecx
				pop ebx
				pop eax
			jnz short mmgSeekThisMember_b

			test [eax].memb_flags,ecx
			jnz short @f
			xor eax,eax
			jmp  mmgExit;short
		@@:
			test ecx,access_type
			xor ebx,ebx
			dec ecx
			jnz short @f
			mov bl,3	;var type
		@@:
			dec ecx
			jnz short @f
			mov bl,3	;var type
		@@:
			dec ecx
			jnz short @f
			mov bl,0	;func
		@@:
			mov [eax].memb_type,ebx
			jmp  mmgExit;short
		mmgSeekThisMember_e:

	mmgAddNewMemberToModule:
			mov esi,lpModule
			test [esi].module_flags,MOD_FL_LUA
			jz short mmgAddNotLuaModuleMember	;eax already 0

				push ebx
				push ecx
		_@getMem sizeof _@module_member
			test eax,eax
				pop ecx
				pop ebx
			jz  mmgExit;short

			mov [eax].memb_flags,MOD_MEMB_ACCESS_READ or MOD_MEMB_ACCESS_WRITE or MOD_MEMB_ACCESS_CALL ;ecx
			mov [eax].lpModule,esi

			push dword ptr [edi]
			mov dword ptr [edi],eax
			pop [eax].lpNextModuleMember

			push eax
			lea edi,[eax].lpszModMembName

			push ebx
			call CloneString

			mov dword ptr [edi],eax
			pop eax

			jmp  mmgExit;short

	mmgAddNotLuaModuleMember:
;int 3
			push [esi].lpszModuleName
			call get_bin_module_interf
			test eax,eax
			jz  mmgExit;short

			mov esi,dword ptr [eax+_@module_link.lpModule]
			push esi

			call IsThisModule
			test eax,eax
			jz  mmgExit;short
			
			add esi,dword ptr [esi+2]
			add esi,MOD_INTERF_CREATING_OFFSET
		_@get_bin_mod_len	;interf len
		_@get_bin_mod_len	;module interf len
			mov ecx,esi
			add ecx,eax	;ecx=mod interf len
		_@get_bin_mod_len	;module name len
			add esi,eax
		_@get_bin_mod_len	;module doc len
			add esi,eax
		_@get_bin_mod_len	;module r func len
			add esi,eax
		_@get_bin_mod_len	;module w func len
			add esi,eax
		_@get_bin_mod_len	;module c func len
			add esi,eax

	mmgSeekTheNeededModuleMember_b:
			xor eax,eax
			
			cmp esi,ecx
			jnc  mmgExit;short

		_@get_bin_mod_len	;module memb len
			test eax,eax
			jz short mmgSeekTheNeededModuleMember_b
			mov ebx,esi
			add ebx,eax
		_@get_bin_mod_len	;module memb name len
			test eax,eax
			jnz short @f
		mmgGotoNextModMemb:
			mov esi,ebx
			jmp short mmgSeekTheNeededModuleMember_b
		@@:
				push eax
			push ebx
			push ecx

			push lpSzMembName
			push esi
			call strcmp

			pop ecx
			pop ebx

			test eax,eax
				pop eax
			jnz short mmgGotoNextModMemb
				add esi,eax

	mmgAddNotLuaModMembProcess:
				push ebx
				push ecx
		_@getMem sizeof _@module_member
			test eax,eax
				pop ecx
				pop ebx
			jz  mmgExit;short

			mov [eax].memb_flags,MOD_MEMB_ACCESS_READ or MOD_MEMB_ACCESS_WRITE or MOD_MEMB_ACCESS_CALL ;ecx
			mov edi,lpModule
		assume edi: ptr _@module
			mov [eax].lpModule,edi

			lea edi,[edi].lpFirstMember
			push dword ptr [edi]
			mov dword ptr [edi],eax
			pop [eax].lpNextModuleMember

			push eax
			mov edi,eax
		assume edi: ptr _@module_member

			push lpSzMembName
			call CloneString

			mov [edi].lpszModMembName,eax
;skip the mod memb doc
		_@get_bin_mod_len
			add esi,eax
;get the mod memb type
			lodsb
			mov [edi].memb_type,eax
;if mod memb type == func (0) fill the props/rets fields
			test al,al
			jnz short mmgAfterFillPropsRetsFields
		_@get_bin_mod_len
			test eax,eax
			jz short mmgAfterFillPropsRetsFields
	mmgFillPropsFields:
		_@get_bin_mod_len ;props count
			mov [edi].func_params_types_list_len,eax
				push eax
		_@getMem eax
			mov [edi].lp_func_params_types_list,eax
			mov ebx,eax
				pop ecx
			inc ecx
		@@:
			dec ecx
			jz short mmgFillRetsFields

			lodsb
			mov byte ptr [ebx],al
			inc ebx
			jmp short @b
	mmgFillRetsFields:
		_@get_bin_mod_len ;rets count
			mov [edi].func_returns_types_list_len,eax
				push eax
		_@getMem eax
			mov [edi].lp_func_returns_types_list,eax
			mov ebx,eax
				pop ecx
			inc ecx
		@@:
			dec ecx
			jz short mmgAfterFillPropsRetsFields

			lodsb
			mov byte ptr [ebx],al
			inc ebx
			jmp short @b
			
	mmgAfterFillPropsRetsFields:
			pop eax


	mmgSeekTheNeededModuleMember_e:
			
	mmgExit:
			pop ecx
			pop ebx
			pop esi
			pop edi
			ret
module_memb_get		endp
;----------------------------------------------------
module_memb_convert_type proc lpszType
			push esi

			mov eax,0ffh
			mov esi,lpszType
			test esi,esi
			jz  mmctExit;short
			mov ah,3

	mmctConvertTypeLoop_b:
			lodsb
			test al,al
			jz short mmctConvertTypeLoop_e

			cmp al,'p'
			jnz short @f
			or ah,40	;bit 6=1
			jmp short mmctConvertTypeLoop_b
		@@:
			cmp al,'b'
			jnz short @f
			and ah,0f8h
			or ah,1
			jmp short mmctConvertTypeLoop_e
		@@:
			cmp al,'w'
			jnz short @f
			and ah,0f8h
			or ah,2
			jmp short mmctConvertTypeLoop_e
		@@:
			cmp al,'d'
			jnz short @f
			and ah,0f8h
			or ah,3
			jmp short mmctConvertTypeLoop_e
		@@:
			cmp al,'s'
			jnz short @f
			and ah,0f8h
			or ah,7
			jmp short mmctConvertTypeLoop_e
		@@:
			cmp al,'f'
			jnz short @f
			mov ah,0
			jmp short mmctConvertTypeLoop_e
		@@:
			cmp al,'r'	;float
			jnz short @f
			and ah,0f8h
			or ah,80h
			jmp short mmctConvertTypeLoop_e
		@@:
			cmp al,'s'	;signed
			jnz short @f
			test ah,7
			jz short mmctConvertTypeLoop_b
			or ah,80h
			jmp short mmctConvertTypeLoop_b
		@@:
			cmp al,'u'	;unsigned
			jnz short @f
			test ah,7
			jz short mmctConvertTypeLoop_b
			and ah,7fh
			jmp short mmctConvertTypeLoop_b
		@@:
			jmp short mmctConvertTypeLoop_b
	mmctConvertTypeLoop_e:
			test al,al
			jz short @f

			lodsb
		@@:
			xchg al,ah
			sub esi,lpszType
			shl esi,16
			or eax,esi

	mmctExit:
			pop esi
			ret
module_memb_convert_type	endp
;----------------------------------------------------
module_memb_set_type	proc lpModMemb,lpszType
			push edi
			push esi
			push ecx

			mov eax,lpModMemb
			test eax,eax
			jz  mmstExit;short
			mov edi,eax
		assume edi: ptr _@module_member

			push lpszType
			call module_memb_convert_type

			mov [edi].memb_type,eax

			test al,al
			jnz  mmstExit;short

			test ah,ah
			jz  mmstExit;short

			cmp ah,':'
			jnz  mmstExit;short

	;		xor ah,ah
			shr eax,16
			add eax,lpszType
			mov lpszType,eax

			mov esi,eax
	;		mov ecx,eax

;func param types
 			lodsb
 
 			cmp al,0
			jz  mmstFuncRetTypes_e;short

 			cmp al,":"
			jz short mmstFuncParTypes_e

 			dec esi
			
 	;		push ecx
 			push eax
 			_@getMem 1000h
			mov [edi].lp_func_params_types_list,eax
			pop eax
	;		pop ecx
			
 			push edi
 			mov edi,[edi].lp_func_params_types_list
		mmstFuncParTypesParse_b:
			cmp al,':'
			jz short mmstFuncParTypesParse_e
			cmp al,0
			jz short mmstFuncParTypesParse_e

			push esi
			call module_memb_convert_type
			stosb
			xchg al,ah
			push eax
			shr eax,16
			add esi,eax
			pop eax
			jmp short mmstFuncParTypesParse_b
		mmstFuncParTypesParse_e:
			mov ecx,eax
			xor al,al
			stosb
			mov eax,ecx
			mov ecx,edi
			pop edi
 			push eax
			sub ecx,[edi].lp_func_params_types_list
			dec ecx
 			mov [edi].func_params_types_list_len,ecx
 			inc ecx
 			mov eax,[edi].lp_func_params_types_list
 			_@regetMem eax,ecx
 			mov [edi].lp_func_params_types_list,eax
 			pop eax
		mmstFuncParTypes_e:

;func ret types
 	;		xchg al,ah

 			xor ecx,ecx
			mov [edi].lp_func_returns_types_list,ecx
 			mov [edi].func_returns_types_list_len,ecx
 
 			cmp al,0
			jz short mmstFuncRetTypes_e
			lodsb
			dec esi
 			cmp al,0
			jz short mmstFuncRetTypes_e
 			cmp al,":"
			jz short mmstFuncRetTypes_e
 			cmp al,";"
			jz short mmstFuncRetTypes_e

 	;		push ecx
 			push eax
 			_@getMem 1000h
			mov [edi].lp_func_returns_types_list,eax
			pop eax
	;		pop ecx
			
 			push edi
 			mov edi,[edi].lp_func_returns_types_list
		mmstFuncRetTypesParse_b:
			cmp al,0
			jz short mmstFuncRetTypesParse_e
			cmp al,':'
			jz short mmstFuncRetTypesParse_e
			cmp al,';'
			jz short mmstFuncRetTypesParse_e

			push esi
			call module_memb_convert_type
			stosb
			xchg al,ah
			push eax
			shr eax,16
			add esi,eax
			pop eax
			jmp short mmstFuncRetTypesParse_b
		mmstFuncRetTypesParse_e:
			xor al,al
			stosb
			mov ecx,edi
			pop edi
 			sub ecx,[edi].lp_func_returns_types_list
 			dec ecx
 			mov [edi].func_returns_types_list_len,ecx
 			inc ecx
 			mov eax,[edi].lp_func_returns_types_list
 			_@regetMem eax,ecx
 			mov [edi].lp_func_returns_types_list,eax
		mmstFuncRetTypes_e:

	mmstExit:
			pop ecx
			pop esi
			pop edi
			ret
 module_memb_set_type	endp
;----------------------------------------------------
module_memb_set_fixe	proc lpModMemb,fixe
			push edi
			push ecx

			mov eax,lpModMemb
			test eax,eax
			jz short mmsfExit
			mov edi,eax
		assume edi: ptr _@module_member

		_@getMem sizeof _@module_fixe
			test eax,eax
			jz short mmsfExit
		assume eax: ptr _@module_fixe

			push fixe
			pop [eax].addr_to_fixe

			push [edi].lpFirstFixe
			mov [edi].lpFirstFixe,eax
			pop [eax].lpNextFixe

	mmsfExit:
			pop ecx
			pop edi
			ret
 module_memb_set_fixe		endp
;----------------------------------------------------
module_memb_set_postfixe	proc lpModMemb,fixe,access_type,id
			push edi
			push esi
			push ecx

			mov eax,lpModMemb
			test eax,eax
			jz short mmsfExit
			mov edi,eax
		assume edi: ptr _@module_member

			mov eax,access_type
			test eax,eax
			jz short mmsfExit

		mmspfIsAccessRead:
			dec eax
			jnz short mmspfIsAccessWrite

			lea esi,[edi].lpFirstPostfixe_r
			jmp short mmspfSetPostfixeProcess

		mmspfIsAccessWrite:
			dec eax
			jnz short mmspfIsAccessCall

			lea esi,[edi].lpFirstPostfixe_w
			jmp short mmspfSetPostfixeProcess

		mmspfIsAccessCall:
			dec eax
			jnz short mmspfIsAccess???

			lea esi,[edi].lpFirstPostfixe_c
			jmp short mmspfSetPostfixeProcess

		mmspfIsAccess???:
			xor eax,eax
			jmp short mmsfExit

	mmspfSetPostfixeProcess:
			mov eax,dword ptr [esi]
		assume eax: ptr _@module_fixe
			mov ecx,id
		@@:
			test eax,eax
			jz short @f
			cmp [eax].id,ecx
			jz short mmspfStoreFixe
			mov eax,[eax].lpNextFixe
			jmp short @b
		@@:

		_@getMem sizeof _@module_fixe
			test eax,eax
			jz short mmsfExit
		assume eax: ptr _@module_fixe

			push id
			pop [eax].id

			push dword ptr [esi]
			mov dword ptr [esi],eax
			pop [eax].lpNextFixe

	mmspfStoreFixe:
			push fixe
			pop [eax].addr_to_fixe

	mmsfExit:
			pop ecx
			pop esi
			pop edi
			ret
 module_memb_set_postfixe	endp
;----------------------------------------------------
;----------------------------------------------------
;----------------------------------------------------
;----------------------------------------------------
;----------------------------------------------------
;----------------------------------------------------
;----------------------------------------------------
;----------------------------------------------------

